<?php
//рус
abstract class response_prototype_class
{
    protected $_body = '';
    protected $_libs;
    
    public function __construct ()
    {
        $this->RegisterOutputFilter('absoluteUrl', array($this, 'SetAbsoluteUrl'));
    }
    
    /**
		обёртка для вызова библиотек
	*/
    protected function Libs()
    {
    	if (!$this->_libs)	$this->_libs = SysLoader::GetLibCollection(); 
    	return $this->_libs;   	
    }     
    
    /**
		устанавливает тело ответа
     */
    public function SetBody ($body)
    {
        //if (!is_string($body)) throw new Exception('Неверный тип контента');
        $this->_body = $body;
    }
    /**
		возвращает тело ответа
     */
    public function GetBody ()
    {
        return $this->_body;
    }
    
    static private $_outputFilters = array();
    
    public function RegisterOutputFilter($name, $callback)
    {
    	self::$_outputFilters[$name] = $callback;
    }
    
    protected function RunOutputFilters()
    {
    	$body = $this->GetBody();
    	foreach (self::$_outputFilters as $callback) 
    	{
    		$body = call_user_func($callback, $body);
    	}
    	
    	self::$_outputFilters = array();
    	
    	$this->SetBody($body);
    }    
    
    /**
     * Send the response, including all headers, rendering exceptions if so
     * requested.
     *
     * @return void
     */
    public function GetResponse()
    {
    	$this->RunOutputFilters();
        return $this->GetBody();    	
    }
    
    public function SendResponse ()
    {
		echo $this->GetResponse();
    }
    
    public function SetAbsoluteUrl($content)
    {
    	return $this->Libs()->str->SetAbsoluteUrls($content);
    }
}